namespace Beaker.OpenCube.CubeManager.Model.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Initial : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Machine",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Name = c.String(maxLength: 64),
                        IPAddress = c.String(maxLength: 45),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Server",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Name = c.String(nullable: false, maxLength: 64),
                        MegabytesOfMemory = c.Int(nullable: false),
                        FullDomainName = c.String(maxLength: 253),
                        PortNumber = c.Int(nullable: false),
                        MaxPlayers = c.Int(nullable: false),
                        HostingMachineId = c.Guid(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Machine", t => t.HostingMachineId, cascadeDelete: true)
                .Index(t => t.HostingMachineId);
            
            CreateTable(
                "dbo.RoleSet",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        User_Id = c.Guid(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.User", t => t.User_Id, cascadeDelete: true)
                .Index(t => t.User_Id);
            
            CreateTable(
                "dbo.User",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Name = c.String(nullable: false, maxLength: 64),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Role",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Name = c.String(nullable: false, maxLength: 64),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Activity",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Name = c.String(nullable: false, maxLength: 64),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.ActivityRoles",
                c => new
                    {
                        Activity_Id = c.Guid(nullable: false),
                        Role_Id = c.Guid(nullable: false),
                    })
                .PrimaryKey(t => new { t.Activity_Id, t.Role_Id })
                .ForeignKey("dbo.Activity", t => t.Activity_Id, cascadeDelete: true)
                .ForeignKey("dbo.Role", t => t.Role_Id, cascadeDelete: true)
                .Index(t => t.Activity_Id)
                .Index(t => t.Role_Id);
            
            CreateTable(
                "dbo.RoleRoleSets",
                c => new
                    {
                        Role_Id = c.Guid(nullable: false),
                        RoleSet_Id = c.Guid(nullable: false),
                    })
                .PrimaryKey(t => new { t.Role_Id, t.RoleSet_Id })
                .ForeignKey("dbo.Role", t => t.Role_Id, cascadeDelete: true)
                .ForeignKey("dbo.RoleSet", t => t.RoleSet_Id, cascadeDelete: true)
                .Index(t => t.Role_Id)
                .Index(t => t.RoleSet_Id);
            
            CreateTable(
                "dbo.ServerRoleSets",
                c => new
                    {
                        Server_Id = c.Guid(nullable: false),
                        RoleSet_Id = c.Guid(nullable: false),
                    })
                .PrimaryKey(t => new { t.Server_Id, t.RoleSet_Id })
                .ForeignKey("dbo.Server", t => t.Server_Id, cascadeDelete: true)
                .ForeignKey("dbo.RoleSet", t => t.RoleSet_Id, cascadeDelete: true)
                .Index(t => t.Server_Id)
                .Index(t => t.RoleSet_Id);
            
            CreateTable(
                "dbo.MachineRoleSets",
                c => new
                    {
                        Machine_Id = c.Guid(nullable: false),
                        RoleSet_Id = c.Guid(nullable: false),
                    })
                .PrimaryKey(t => new { t.Machine_Id, t.RoleSet_Id })
                .ForeignKey("dbo.Machine", t => t.Machine_Id, cascadeDelete: true)
                .ForeignKey("dbo.RoleSet", t => t.RoleSet_Id, cascadeDelete: true)
                .Index(t => t.Machine_Id)
                .Index(t => t.RoleSet_Id);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.MachineRoleSets", new[] { "RoleSet_Id" });
            DropIndex("dbo.MachineRoleSets", new[] { "Machine_Id" });
            DropIndex("dbo.ServerRoleSets", new[] { "RoleSet_Id" });
            DropIndex("dbo.ServerRoleSets", new[] { "Server_Id" });
            DropIndex("dbo.RoleRoleSets", new[] { "RoleSet_Id" });
            DropIndex("dbo.RoleRoleSets", new[] { "Role_Id" });
            DropIndex("dbo.ActivityRoles", new[] { "Role_Id" });
            DropIndex("dbo.ActivityRoles", new[] { "Activity_Id" });
            DropIndex("dbo.RoleSet", new[] { "User_Id" });
            DropIndex("dbo.Server", new[] { "HostingMachineId" });
            DropForeignKey("dbo.MachineRoleSets", "RoleSet_Id", "dbo.RoleSet");
            DropForeignKey("dbo.MachineRoleSets", "Machine_Id", "dbo.Machine");
            DropForeignKey("dbo.ServerRoleSets", "RoleSet_Id", "dbo.RoleSet");
            DropForeignKey("dbo.ServerRoleSets", "Server_Id", "dbo.Server");
            DropForeignKey("dbo.RoleRoleSets", "RoleSet_Id", "dbo.RoleSet");
            DropForeignKey("dbo.RoleRoleSets", "Role_Id", "dbo.Role");
            DropForeignKey("dbo.ActivityRoles", "Role_Id", "dbo.Role");
            DropForeignKey("dbo.ActivityRoles", "Activity_Id", "dbo.Activity");
            DropForeignKey("dbo.RoleSet", "User_Id", "dbo.User");
            DropForeignKey("dbo.Server", "HostingMachineId", "dbo.Machine");
            DropTable("dbo.MachineRoleSets");
            DropTable("dbo.ServerRoleSets");
            DropTable("dbo.RoleRoleSets");
            DropTable("dbo.ActivityRoles");
            DropTable("dbo.Activity");
            DropTable("dbo.Role");
            DropTable("dbo.User");
            DropTable("dbo.RoleSet");
            DropTable("dbo.Server");
            DropTable("dbo.Machine");
        }
    }
}
